<template>
  <div>
    <el-table
      :data="menuList"
      style="width: 100%"
      row-key="id"
      border
      lazy
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="菜单编号"> </el-table-column>
      <el-table-column prop="title" label="菜单名称"> </el-table-column>
      <el-table-column label="菜单图标">
        <template slot-scope="scope">
          <div>
            <i :class="scope.row.icon"></i>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="菜单地址"> </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button v-if="scope.row.status == 1" type="danger" > 启用 </el-button>
            <el-button v-else type="success"> 禁用 </el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <div>
            <el-button @click="dit(scope.row.id)">编辑</el-button>
            <el-button @click="del(scope.row.id)">删除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import {successAlert,warningAlert}from "../../../util/alter"
import { mapGetters, mapActions } from "vuex";
//引入删除接口
import {menuDel} from '../../../requster/api'

export default {
  data() {
    return {
      arr: [],
    };
  },

  methods: {
    ...mapActions({
      reqmenulist: "menu/reqChangeList",
    }),

    // 删除事件
    del(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          menuDel({id:id}).then(res=>{
           if(res.data.code==200){

             successAlert(res.data.msg)
            //  重新渲染页面
            this.reqmenulist()
           }else{
             warningAlert(res.data.msg)
           }
          })
          
        })
        .catch(() => {
          warningAlert("取消删除")
        });
    },
    // 编辑事件
    dit(id){
      this.$emit("dit",id)
    }

  },

  computed: {
    ...mapGetters({
      menuList: "menu/list",
    }),
  },
  mounted() {
    console.log(this.menuList);
    this.reqmenulist();
  },
};
</script>

<style>
</style>